package com.pms.mapper;

import com.github.pagehelper.Page;
import com.pms.dto.UserPageQueryDTO;
import com.pms.entity.User;
import com.pms.vo.UserPageQueryVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select id, username, password, phone, roles, avatar, status_id as statusId from user where username=#{username}")
    User getByUsername(String username);

    /**
     * 插入新注册用户信息
     * @param user
     */
    @Insert("insert into user(username, password, phone, roles) values (#{username},#{password},#{phone},#{roles})")
    void setUser(User user);

    /**
     * 根据主键动态修改用户信息
     * @param user
     */
    void update(User user);

    /**
     * 根据主键查询用户信息
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    User getUserById(Integer id);

    /**
     * 用户分页查询
     * @param userPageQueryDTO
     * @return
     */
    Page<UserPageQueryVO> page(UserPageQueryDTO userPageQueryDTO);

    /**
     * 根据id删除
     * @param id
     */
    @Delete("delete from user where id=#{id}")
    void delete(Integer id);
}
